package com.situ.stmall.controller.api;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.situ.stmall.entity.APIResult;
import com.situ.stmall.entity.Shopcart;
import com.situ.stmall.entity.User;
import com.situ.stmall.service.ShopcartService;

@RestController
@RequestMapping("/api/cart")
public class APICartcontroller {
	
	@Autowired
	private ShopcartService shopcartService;

	@GetMapping("/getAll")
	public List getAll(HttpSession session) {
		//参数
		User user = (User) session.getAttribute("user");
		//service
		return shopcartService.getByUserId(user.getId());
		//返回
	}
	
	@GetMapping("/upload")
	public APIResult update(Shopcart cart) {
		
		int res = shopcartService.update(cart);
		
		if (res>0) {
			return APIResult.ok(null);
		}else {
			return APIResult.notFound("购物车修改失败");
		}
		
	}
}
